package com.yichen.rent.controller;

import com.yichen.rent.service.PdfService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

@RestController
@RequestMapping("export")
public class ExportPdfController {

    @Autowired
    private PdfService pdfService;

    @RequestMapping("/contract/pdf/{contractId}")
    public ResponseEntity<byte[]> exportPdf(@PathVariable("contractId") String contractId, HttpServletResponse response) throws Exception {
        return pdfService.generatePDFFileTwo(contractId,response);
        /*//设置响应contenType
        response.setContentType("application/octet-stream");
        //设置响应文件名称
        String fileName = new String("申请表.doc".getBytes("UTF-8"),"iso-8859-1");
        //设置文件名称
        response.setHeader("Content-Disposition", "attachment; filename="+fileName);
        //获取输出流
        OutputStream out = response.getOutputStream();
        String test = "ajlksdjflakjdfasdfasdfsadjfajdfslf 斯洛伐克静安里看到df";
        byte[] bytes = test.getBytes();
        ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();
        pdfOutputStream.write(bytes);
        pdfOutputStream.writeTo(out);
        pdfOutputStream.close();
        out.flush();
        out.close();*/
    }
}
